<?php
/**
 * IG_Controller_Action
 *
 * @author maomao.thx@gmail.com
 * @copyright Copyright (c) 2009 Green Shore (http://www.iwgame.com)
 * @version $Id: Action.php 881 2011-09-30 05:46:19Z mmxie $
 */
class IG_Controller_Action extends Zend_Controller_Action
{
    /**
     * 获取当前登录的用户
     *
     * @return System_Model_Employee
     */
    protected function getIdentity()
    {
        return Zend_Auth::getInstance()->getIdentity();
    }

    protected function setRender($url = null)
    {
        if (null === $url) {
            $this->_helper->ViewRenderer->setNoRender();
        } else {
            $this->_helper->ViewRenderer->renderScript($url);
        }
    }

    protected function setNoRender()
    {
        $this->_helper->ViewRenderer->setNoRender();
    }

    protected function disableLayout()
    {
        $this->_helper->layout->disableLayout();
    }

    /**
     * Gets a parameters from the {@link $_request Request object}.  If the
     * parameter does not exist, NULL will be returned.
     *
     * If the parameter does not exist and $default is set, then
     * $default will be returned instead of NULL.
     *
     * @param array $defaultParams
     * @return array
     * @example
     * <code>
     * &lt;php
     * //提交数据  name=hello&date=&title=
     * $params = $this->_getParams(array('name', 'date' => date('Y-m-d'), 'title'));
     * print_r($params);
     * ?&gt;
     * </code>
     * <code>
     * 输出结果:
     * Array (
     *     [name] => hello,
     *     [date] => 2011-01-01
     *     [title] =>
     * )
     * </code>
     *
     */
    protected function _getParams($defaultParams = array())
    {
        if (!empty($defaultParams)) {
            $params = array();
            foreach ($defaultParams as $key => $default) {
                if (is_int($key)) {
                    $key = $default;
                    $default = null;
                }
                $params[$key] = $this->_getParam($key, $default);
            };

            return $params;
        }

        return parent::_getAllParams();
    }
}